package com.lelouch.wetlandaccount.service.impl;

import com.lelouch.wetlandaccount.repository.UserEntityRepository;
import com.lelouch.wetlandaccount.service.UserEntityService;
import com.lelouch.wetlandcommon.domain.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lcy
 * @create 2018-09-04 15:27
 */
@Service
public class UserEntityServiceImpl implements UserEntityService {
    @Autowired
    private UserEntityRepository userEntityRepository;

    public UserEntity add(UserEntity userEntity){
       return userEntityRepository.save(userEntity);

    }

    public boolean delete(String id){
        userEntityRepository.deleteById(id);
        if(userEntityRepository.existsById(id)){
            return false;
        }else{
            return true;
        }
    }

    public UserEntity update(UserEntity userEntity){
        return userEntityRepository.save(userEntity);
    }

    public UserEntity findById(String id){
        return userEntityRepository.findById(id).get();
    }

    public UserEntity findByUsername(String username){
       return userEntityRepository.findByUserName(username);
    }
}
